package com.woniu.controller;

import com.woniu.entity.PageResult;
import com.woniu.entity.Result;
import com.woniu.pojo.PrivateTimetable;
import com.woniu.service.IPrivateTimetableService;
import com.woniu.vo.AppChangeQueryVo;
import com.woniu.vo.PrivateTimetableAddVo;
import com.woniu.vo.PrivateTimetableQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaohuang
 * @since 2022-10-12
 */
@RestController
@RequestMapping("/privateTimetable")
@Api(tags = "私课课表管理")
public class PrivateTimetableController extends BaseController{
    @Autowired
    private IPrivateTimetableService privateTimetableService;

    @ApiOperation("添加")
    @PostMapping
    public Result save(@RequestBody PrivateTimetableAddVo privateTimetableAddVo){
        Integer row = privateTimetableService.saveTimetable(privateTimetableAddVo);
        return toResult(row);
    }

    @ApiOperation("查询")
    @GetMapping("/{id}")
    public Result getById(@PathVariable String id){
        PrivateTimetable privateTimetable = privateTimetableService.getById(id);
        return toDataResult(privateTimetable);
    }

    @ApiOperation("修改")
    @PutMapping
    public Result modify(@RequestBody PrivateTimetable privateTimetable){
        boolean flag = privateTimetableService.updateById(privateTimetable);
        return toResult(flag);
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable String id){
        Integer row = privateTimetableService.deleteById(id);
        return toResult(row);
    }

    @ApiOperation("分页条件查询")
    @PostMapping("findByPage/{currentPage}/{pageSize}")
    public Result findByPage(@PathVariable Integer currentPage,
                             @PathVariable Integer pageSize,
                             @RequestBody(required = false) PrivateTimetableQueryVo timetableQueryVo){
        PageResult pageResult = privateTimetableService.search(currentPage,pageSize,timetableQueryVo);
        return toDataResult(pageResult);
    }

    @ApiOperation("根据场馆id查询")
    @GetMapping("/app/{gymId}")
    public Result findByGymId(@PathVariable String gymId){
        PageResult pageResult = privateTimetableService.findByGymId(gymId);
        return toDataResult(pageResult);
    }

    @ApiOperation("根据课表id查询")
    @GetMapping("/app/timetable/{id}")
    public Result findByTimetableId(@PathVariable String id){
        AppChangeQueryVo appChangeQueryVo = privateTimetableService.findByTimetableId(id                                                 );
        return toDataResult(appChangeQueryVo);
    }
}
